import { createRouter, createWebHistory } from "vue-router";
import Main from "../components/Main.vue";
import layout from "../layout/index.vue";
import { cookie } from "../utils/cookie";
import GLOBAL from "../utils/globelConfig";

const routes = [
  {
    path: "/static/module1/",
    name: "layout",
    component: layout,
    redirect: "/static/module1/main",
    children: [
      {
        path: "/static/module1/main",
        name: "首页",
        component: Main,
      },
    ],
  },
];

const router = createRouter({
  history: createWebHistory(),
  routes,
});
router.beforeEach((to, _from, next) => {
  console.log("AUTHORIZATION", cookie.get("AUTHORIZATION"));
  console.log("to", to);
  if (!cookie.get("AUTHORIZATION")) {
    window.location.href = GLOBAL.LOGIN_URL;
  } else {
    // if (to.path.split("/").indexOf("static") > -1) {
    //   let nextList = "/";
    //   if (to.path.split("/").length >= 4) {
    //     to.path.split("/").map((item, index) => {
    //       if (index >= 3 && item !== "") {
    //         nextList += item + "/";
    //       }
    //     });
    //   }
    //   console.log("nextList", nextList);
    //   next(nextList);
    //   return;
    // } else {
      next();
      return;
    // }
  }
});
export default router;
